package com.fine.demo.keyboard

import android.content.Context
import android.view.inputmethod.InputMethodManager
import android.widget.EditText

object SystemUtil {

    fun closeKeyboard(context: Context) {
        val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
        imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.RESULT_HIDDEN)
    }

    fun showKeyboard(context: Context) {
        val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
        if(!imm.isActive) {
            imm.toggleSoftInput(0, InputMethodManager.RESULT_SHOWN)
        }
    }

    fun closeKeyboard(edit: EditText) {
        val imm = edit.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
        if(imm.isActive) {
            imm.hideSoftInputFromWindow(edit.windowToken, 0)
        }
    }

}